<include file="Public/head"/>
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<script src="http://img1.isou365.cn/paimai/yunying/js/city.js" type="text/javascript"></script>
<style>
    .xuanzhe ul li .menDao1{width:300px;}
    .xuanzhe ul li .menDao1 a{display:block;background:#cecece;color:#303030;float:left;width:36px; text-align:center;height:20px; line-height:20px; cursor:pointer;}
    .xuanzhe ul li .menDao1 .menHover{ background:#20ab4f;color:#fff;}
</style>
<include file="Public/common_header"/>
<div class="mian">
    <include file="Public/sidebar" menu="jybggl.tcgl"/>
    <div class="mianR">
        <div class="listBox">
                <h3 class="cha">退车详情</h3>
            <div class="car_info">
                    <div class="car_no"><span style="font-size:14px;">车辆编号：<b>{$detail.sno}</b></span></div>

                    <table border="1" width="100%">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;"><span>车主信息</span></td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">车主姓名</td>
                            <td width="39%">{$detail.seller_name}</td>
                            <td width="11%" style="color:#898b8a;">联系电话</td>
                            <td colspan="3">{$detail.phone}</td>
                        </tr>
                        </tbody>
                    </table>

                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                            <tr>
                                <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                                    <span>车辆信息</span>
                                    <span style="float: right;margin-right: 20px;"><a style="color: #0000FF;text-decoration: underline;" href="/Car/report/car_id/{$detail.car_id}" target="_blank">检测报告</a></span>
                                </td>
                            </tr>
                            <tr>
                                <td width="11%" style="color:#898b8a;">车型</td>
                                <td width="39%">{$detail.model}</td>
                                <td width="11%" style="color:#898b8a;">排放标准</td>
                                <td width="39%">{$detail.emission}</td>
                            </tr>
                            <tr>
                                <td style="color:#898b8a;">初登日期</td>
                                <td>{$detail.first_reg_date}</td>
                                <td style="color:#898b8a;">颜色</td>
                                <td>{$detail.car_color}</td>
                            </tr>
                            <tr>
                                <td style="color:#898b8a;">表显里程</td>
                                <td>{$detail.pointer_mileage}万公里</td>
                                <td style="color:#898b8a;">车况级别</td>
                                <td>{$detail.composite_state}{$detail.accident_level}</td>
                            </tr>
                            <tr>
                                <td style="color:#898b8a;">车辆注册地</td>
                                <td>{$detail.first_reg_city}</td>
                                <td style="color:#898b8a;">车架号</td>
                                <td>{$detail.vin}</td>
                            </tr>
                            <tr>
                                <td style="color:#898b8a;">过户限制</td>
                                <td>{$detail.transfer_limit}</td>
                                <td style="color:#898b8a;">车牌号</td>
                                <td>{$detail.plate_prefix}{$detail.plate_suffix}</td>
                            </tr>
                            <tr>
                                <td style="color:#898b8a;">渠道来源</td>
                                <td>
                                    <if condition="$detail.comefrom neq ''">
                                        <?php if(empty($detail['comefrom_url'])):?>
                                        {$detail.comefrom}
                                        <?php else: ?>
                                        <a href="{$detail.comefrom_url}" target="_blank" rel="noreferrer">{$detail.comefrom}</a>
                                        <?php endif;?>
                                        <else/>
                                        未知
                                    </if>
                                </td>
                                <td style="color:#898b8a;">所在地</td>
                                <td>{$detail.location_area}</td>
                            </tr>
                        </tbody>
                    </table>

                <table border="1" width="100%" style="margin-top:10px;">
                    <tbody>
                    <tr>
                        <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                            <span>车辆处理信息</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="11%" style="color:#898b8a;">提交人</td>
                        <td width="39%">{$detail.emp_name}</td>
                        <td width="11%" style="color:#898b8a;">提交时间</td>
                        <td width="39%">{$detail.create_time}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">退车原因</td>
                        <td>{$detail.back_reason}</td>
                        <td style="color:#898b8a;">车辆类型</td>
                        <td>{$detail.type}</td>
                    </tr>
                    <tr>
                        <td style="color:#898b8a;">退车备注</td>
                        <td colspan="3">{$detail.remark}</td>
                    </tr>
                    </tbody>
                </table>

            </div>

            <?php if($status == 3):?>
                <div class="car_info">
                    <table border="1" width="100%" style="margin-top:10px;">
                        <tbody>
                        <tr>
                            <td colspan="4" style="background-color:#c1c1c1;font-size:14px;">
                                <span>退车信息</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="11%" style="color:#898b8a;">操作人</td>
                            <td width="39%">{$detail.refundInfo.finish_emp_name}</td>
                            <td width="11%" style="color:#898b8a;">处理时间</td>
                            <td width="39%">{$detail.refundInfo.finish_time}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">代驾公司</td>
                            <td>{$detail.refundInfo.driver_company}</td>
                            <td style="color:#898b8a;">代驾姓名</td>
                            <td>{$detail.refundInfo.driver_name}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">代驾出发时间</td>
                            <td>{$detail.refundInfo.departure_time}</td>
                            <td style="color:#898b8a;">代驾电话</td>
                            <td>{$detail.refundInfo.driver_phone}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">核实手续</td>
                            <td colspan="3">{$detail.refundInfo.procedures}</td>
                        </tr>
                        <tr>
                            <td style="color:#898b8a;">退车备注</td>
                            <td colspan="3">{$detail.refundInfo.remark}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            <?php endif;?>

            <?php if($status == 2):?>
                <h3 class="yonghu" style="margin-top:25px;">系统跟踪日志</h3>
                <div class="yonghuText">
                    <ul>
                        <foreach name="follow_log" item="f">
                            <li class="clearfix">
                                <em>{$f.create_time|strtotime|date='Y-m-d H:i',###}</em>
                                <em>{$f.emp_name}</em>
                                <em>继续跟踪</em>
                                <em class="name-text">{$f.remark}</em>
                            </li>
                        </foreach>
                    </ul>
                </div>
            <?php endif;?>

            <?php if($status != 3):?>
                <h3 class="yonghu">退车结果</h3>
                <div class="listBox">
                    <div class="yuList">
                        <div class="shop_details">
                            <ul>
                                <li>
                                    <span>核实手续</span>
                                    <ul class="procedures">
                                        <foreach name="detail.procedures" item="recheck_procedures">
                                            <?php if(in_array($recheck_procedures,$detail['selected_procedures'])):?>
                                                <li name="procedures" class="current" value="{$recheck_procedures}">{$recheck_procedures}</li>
                                            <?php else:?>
                                                <li name="procedures" value="{$recheck_procedures}">{$recheck_procedures}</li>
                                            <?php endif;?>
                                        </foreach>
                                    </ul>
                                    <span class="checkmark"></span>
                                </li>
                                <li>
                                    <span><i class="review-heart">*</i>代驾公司</span>
                                    <em>
                                        <input type="text" id="driver_company" name="driver_company" placeholder="请输入代驾公司">
                                    </em>
                                </li>
                                <li>
                                    <span><i class="review-heart">*</i>代驾姓名</span>
                                    <em>
                                        <input type="text" id="driver_name" name="driver_name" placeholder="请输入代驾姓名">
                                    </em>
                                </li>
                                <li>
                                    <span><i class="review-heart">*</i>代驾电话</span>
                                    <em>
                                        <input type="text" id="driver_phone" name="driver_phone" placeholder="请输入代驾电话">
                                    </em>
                                </li>
                                <li>
                                    <span>代驾出发时间</span>
                                    <em>
                                        <input type="text" id='departure_time' name="departure_time" placeholder="请选择代驾出发时间">
                                    </em>
                                </li>

                                <li>
                                    <span>备注</span>
                                    <em>
                                        <textarea id="remark" class="remarks_text"></textarea>
                                    </em>
                                </li>
                            </ul>
                        </div>
                        <div class="yongBtn">

                            <input type="button" data-id="1" value="继续跟踪" onclick="continue_follow();"  class="queding">
                            <input type="hidden" name="status" value="1">

                            <!--<?php if($detail['car_source'] == 1):?>

                                <input type="hidden" name="status" value="1">
                            <?php else:?>
                                <input type="button" data-id="2" value="确定" name="queding" class="queding">
                                <input type="hidden" name="status" value="2">
                            <?php endif;?>-->
                            <!--<input type="button" data-id="1" value="继续跟踪" class="queding" onclick="test()">-->
                            <input type="button"  class="quxiao" value="返回">
                        </div>
                    </div>
                </div>
            <?php else:?>
                <div class="yongBtn">
                    <input type="button"  class="quxiao" value="返回">
                </div>
            <?php endif;?>
        </div>
</div>
<script>
    $(document).ready(function(){
        $("#departure_time").ymdateplugin({
            showTimePanel: true,
            changeMonth: true,
            changeYear: true
        });
        $("#next_trace_time").ymdateplugin({
            showTimePanel: true,
            changeMonth: true,
            changeYear: true
        });
        $("#rechecker,#rechecker2").select2();

        //禁用输入代驾公司，代驾姓名等信息
        disableInput();

        //alert($(".procedures li").length);
        if($(".procedures li").length == $(".procedures .current").length){
            enableInput();
        }
        //alert($(".procedures .current").length);

        $(".quxiao").click(function () {
            window.close();
        });

        $(".procedures li").on("click",function(){
            $(this).toggleClass("current");
            var car_source = "<?php echo $detail['car_source'];?>";
            if($(".procedures .current").length == $(".procedures li").length){
                $(".shop_details .checkmark").show();
                $('input[name=status]').val(2);
                $(".yongBtn .queding").attr('data-id','2');
                $(".yongBtn .queding").removeAttr("onclick");
                $(".yongBtn .queding").attr('onclick','submit()');
                $(".yongBtn .queding").val("确定");

                //启用输入代驾公司，代驾姓名等信息
                enableInput();
            }else{
                /*if(car_source == 2){
                    $('input[name=status]').val(2);
                    $(".yongBtn .queding").attr('data-id','2');
                    $(".yongBtn .queding").removeAttr("onclick");
                    $(".yongBtn .queding").attr('onclick','submit()');
                    $(".yongBtn .queding").val("确定");
                }else{
                    $('input[name=status]').val(1);
                    $(".yongBtn .queding").removeAttr("onclick");
                    $(".yongBtn .queding").attr('onclick','continue_follow()');
                    $(".yongBtn .queding").val("继续跟踪");
                }*/
                $('input[name=status]').val(1);
                $(".yongBtn .queding").removeAttr("onclick");
                $(".yongBtn .queding").attr('onclick','continue_follow()');
                $(".yongBtn .queding").val("继续跟踪");

                $(".shop_details .checkmark").hide();

                //禁用输入代驾公司，代驾姓名等信息
                disableInput();
            }
        })
        var oHeight=$(".review-alert").outerHeight();
        $(".review-alert").css("marginTop",-oHeight/2+"px");


        $('[name=queding]').click('click',submit);

        $(".shenhei-btn .cancel").on("click",function(){
            $(".review-alert #recheck_time1").val("");
            $(".review-alert textarea").val("");
            $(".review-alert").fadeOut();
            $(".yunBei").css("display","none");
        })
    });

    //禁用输入代驾公司，代驾姓名等信息
    function disableInput() {
        var arr = ['driver_company','driver_name','driver_phone','departure_time','remark'];
        var length = arr.length;
        for(var i = 0;i< length;i++){
            $('#'+arr[i]).attr("disabled",true);
        }
    }

    //启用输入代驾公司，代驾姓名等信息
    function enableInput() {
        var arr = ['driver_company','driver_name','driver_phone','departure_time','remark'];
        var length = arr.length;
        for(var i = 0;i< length;i++){
            $('#'+arr[i]).attr("disabled",false);
        }
    }
    
    /**
     * 提交
     **/
    function submit() {
            var status = $('input[name=status]').val();
            var url='';
            var postData = {"order_id":"<?php echo $detail['order_id'];?>",status:status};

            postData.car_id = "<?php echo $detail['car_id']?>";
            postData.owner_id = "<?php echo $detail['owner_id'];?>";
            postData.id = "<?php echo $detail['id'];?>";
            //status = 2;
            if(status == 1 ){
                var procedureObj = new Array();
                url='/RefundCar/continueFollow';
                postData.next_trace_time = $("#next_trace_time").val();
                postData.trace_reason = $("#trace_reson").val();
                $("ul li.current").each(function() {
                    procedureObj.push($(this).text());
                });
                postData.procedures = procedureObj.join("、");
                if(postData.next_trace_time==''){
                    shibai_alert("请选择下次跟踪时间!");
                    return;
                }
                if(postData.trace_reason==''){
                    shibai_alert("请输入跟踪原因!");
                    return;
                }
            }else{
                var procedureObj = new Array();

                url='/RefundCar/save';
                postData.driver_company = $("#driver_company").val();
                postData.driver_name = $('#driver_name').val();
                postData.driver_phone = $("#driver_phone").val();
                $("ul li.current").each(function() {
                    procedureObj.push($(this).text());
                });
                postData.procedures = procedureObj.join("、");
                postData.remark = $("#remark").val();
                postData.departure_time = $("#departure_time").val();
               // console.log(postData);return;
                if(postData.driver_company==0){
                    shibai_alert('代驾公司不能为空!');
                    return;
                }
                if(postData.driver_name==''){
                    shibai_alert("代驾姓名不能为空!");
                    return;
                }

                if(postData.driver_phone==''){
                    shibai_alert("代驾电话不能为空!");
                    return;
                }
            }
            $(".yunBei").css("display",'block').unbind('click');
            $(".loading").fadeIn();
            $.post(url,postData,function(data) {
                if(data.code!=200){
                    shibai_alert(data.msg,1500);
                    $(".loading").fadeOut();
                    $(".yunBei").css("display",'none')
                    return false;
                }
                btn_alert("操作成功",1500,function () {
                    window.location.href="/RefundCar/index";
                    //window.close();
                });
            },'json');
    }

    function continue_follow() {
        $(".yunBei").css({"display":'block'});
        $(".review-alert").fadeIn();
    }
</script>
<div class="yunBei"></div>
<div class="review-alert">
    <ul>
        <li><span>下次跟踪时间</span><input id="next_trace_time" type="text" name="next_trace_time" value="" placeholder="请选择下次跟踪时间" readonly="" class="driving_time"></li>
        <li><span>跟踪原因</span><textarea name="trace_reson" id="trace_reson"></textarea></li>
    </ul>
    <div class="shenhei-btn">
        <input type="button" value="确定" data-id = "1" name="queding" class="determine">
        <input type="button" value="取消" class="cancel">
    </div>
</div>
<include file="Public/foot" />